parameters:
- name: spmi_jitoptions_base
  displayName: 'JIT options (base): semicolon separated list in format `A=B;C=D` without DOTNET_ prefix, passed to `superpmi.py -base_jit_option`'
  type: string
  default: ' '
- name: spmi_jitoptions_diff
  displayName: 'JIT options (diff): semicolon separated list in format `A=B;C=D` without DOTNET_ prefix, passed to `superpmi.py -diff_jit_option`'
  type: string
  default: ' '

# This pipeline only runs on GitHub PRs, not on merges.
trigger: none

# Only run on changes to the JIT directory.
pr:
  branches:
    include:
    - main
  paths:
    # If you are changing these and start including eng/common, adjust the Maestro subscriptions
    # so that this build can block dependency auto-updates (this build is currently ignored)
    include:
    - src/coreclr/jit/*

variables:
  - template: /eng/pipelines/common/variables.yml

extends:
  template:  /eng/pipelines/common/templates/pipeline-with-resources.yml
  parameters:
    stages:
    # Don't run if the JIT-EE GUID has changed,
    # since there won't be any SuperPMI collections with the new GUID until the collection
    # pipeline completes after this PR is merged.
    - ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
      - stage: EvaluatePaths
        displayName: Evaluate Paths
        jobs:
        - template: /eng/pipelines/common/evaluate-paths-job.yml
          parameters:
            paths:
            - subset: jiteeversionguid
              include:
              - src/coreclr/inc/jiteeversionguid.h

    - stage: Build
      jobs:

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: checked
          platforms:
          - windows_x64
          - windows_x86
          jobParameters:
            buildArgs: -s clr.alljits+clr.spmi -c $(_BuildConfig)
            postBuildSteps:
              - template: /eng/pipelines/common/upload-artifact-step.yml
                parameters:
                  rootFolder: $(Build.SourcesDirectory)/artifacts/bin/coreclr
                  includeRootFolder: false
                  archiveType: $(archiveType)
                  tarCompression: $(tarCompression)
                  archiveExtension: $(archiveExtension)
                  artifactName: CheckedJIT_$(osGroup)$(osSubgroup)_$(archType)
                  displayName: JIT and SuperPMI Assets
            condition: not(eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_jiteeversionguid.containsChange'], true))

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/common/global-build-job.yml
          buildConfig: release
          platforms:
          - windows_x64
          - windows_x86
          - linux_x64
          jobParameters:
            buildArgs: -s clr.alljits+clr.spmi -c $(_BuildConfig) /p:NoPgoOptimize=true
            postBuildSteps:
              - template: /eng/pipelines/common/upload-artifact-step.yml
                parameters:
                  rootFolder: $(Build.SourcesDirectory)/artifacts/bin/coreclr
                  includeRootFolder: false
                  archiveType: $(archiveType)
                  tarCompression: $(tarCompression)
                  archiveExtension: $(archiveExtension)
                  artifactName: ReleaseJIT_$(osGroup)$(osSubgroup)_$(archType)
                  displayName: JIT and SuperPMI Assets
            condition: not(eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_jiteeversionguid.containsChange'], true))

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/coreclr/templates/superpmi-diffs-job.yml
          buildConfig: checked
          platforms:
          - windows_x64
          - windows_x86
          helixQueueGroup: ci
          helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
          jobParameters:
            condition: not(eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_jiteeversionguid.containsChange'], true))
            diffType: asmdiffs
            baseJitOptions: ${{ parameters.spmi_jitoptions_base }}
            diffJitOptions: ${{ parameters.spmi_jitoptions_diff }}

      - template: /eng/pipelines/common/platform-matrix.yml
        parameters:
          jobTemplate: /eng/pipelines/coreclr/templates/superpmi-diffs-job.yml
          buildConfig: checked
          platforms:
          - windows_x64
          - windows_x86
          - linux_x64
          helixQueueGroup: ci
          helixQueuesTemplate: /eng/pipelines/coreclr/templates/helix-queues-setup.yml
          jobParameters:
            condition: not(eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_jiteeversionguid.containsChange'], true))
            diffType: tpdiff
            baseJitOptions: ${{ parameters.spmi_jitoptions_base }}
            diffJitOptions: ${{ parameters.spmi_jitoptions_diff }}
